package com.atguigu.search.thread;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadTest {

    private static ExecutorService executorService = Executors.newFixedThreadPool(10);
    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
//            System.out.println("异步任务开始");
//            int res = 10 / 2;
//            System.out.println("异步任务结果：" + res);
//        }, executorService);

        CompletableFuture<Integer> future2 = CompletableFuture.supplyAsync(() -> {
            System.out.println("异步任务开始");
            int res = 10 / 2;
            System.out.println("异步任务结果：" + res);
            return res;
        }, executorService);
        System.out.println("方法外的结果" + future2.get());
    }
}
